package com.wjc.train.business.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.business.req.TrainCarriageQueryReq;
import com.wjc.train.business.req.TrainCarriageSaveReq;
import com.wjc.train.business.resp.TrainCarriageQueryResp;
import com.wjc.train.business.service.ITrainCarriageService;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 车厢表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-08-02
 */
@RestController
@Validated
@RequestMapping("/admin/train-carriage")
public class TrainCarriageController {

    @Resource
    private ITrainCarriageService traincarriageService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid TrainCarriageSaveReq traincarriageSaveReq){
        traincarriageService.save(traincarriageSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp save(@RequestBody TrainCarriageQueryReq traincarriageQueryReq){
        IPage<TrainCarriageQueryResp> iPage =
        traincarriageService.queryList(PageUtil.getPage(traincarriageQueryReq.getQueryPage()), traincarriageQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        traincarriageService.delete(id);
        return CommonResp.success();
    }


}


